﻿@using eLoan.Models;
@model PenaltyHistoryModel

@{
    ViewBag.Title = "Penalty History";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Penalty History</h2>
        <ol class="breadcrumb">
            <li>
                Reports
            </li>
            <li class="active">
                <strong>Penalty History</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
            @using (Html.BeginForm("RefreshPenaltyHistory", "Report", FormMethod.Post, new { id = "saveForm" }))
            {
                <fieldset>

                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    
                    <div class="ibox-title">
                        <div class="divSearch">
                            <table class="table-search">
                                <tr>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Branches)</span>
                                        @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "single-line" })
                                    </td>
                                    <td class="tdFixed">
                                        @Html.LabelFor(m => m.LoanDateFrom)
                                        <div class="form-group" id="fd">
                                            <div class="input-group date">
                                                <span class="input-group-addon">
                                                    <i class="fa fa-calendar"></i>
                                                </span>
                                                @Html.TextBoxFor(m => m.LoanDateFrom, "{0:MM/dd/yyyy}", new { @id = "txtFromDate", @class = "form-control" })
                                            </div>
                                        </div>
                                    </td>
                                    <td class="tdFixed">
                                        @Html.LabelFor(m => m.LoanDateTo)
                                        <div class="form-group" id="td">
                                            <div class="input-group date">
                                                <span class="input-group-addon">
                                                    <i class="fa fa-calendar"></i>
                                                </span>
                                                @Html.TextBoxFor(m => m.LoanDateTo, "{0:MM/dd/yyyy}", new { @id = "txtToDate", @class = "form-control" })
                                            </div>
                                        </div>
                                    </td>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.SearchText)</span>
                                        @Html.TextBoxFor(m => m.SearchText, new { @id = "txtSearchText", @class = "single-line" })
                                    </td>
                                    <td class="tdFixed">
                                        <button type="submit" id="btnRefresh" class="btn btn-primary btnSearch" value="Refresh">Search</button>
                                    </td>
                                    <td class="alignright">
                                        <button type="submit" id="btnRefresh" class="btn btn-primary btnSearch" name="command" value="Export">Export to pdf</button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <div class="ibox-title">
                        <div class="pull-left">
                            <h3>Penalty History</h3>
                        </div>
                        <div class="pull-right">
                            <h3>
                                Total Penalty: @Html.ValueFor(m => Model.TotalPenalty, "{0:#,###,##0.00}")
                                @Html.HiddenFor(m => Model.TotalPenalty)
                            </h3>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <table class="table table-bordered table-List">
                            <thead>
                                <tr>
                                    <th>Borrower</th>
                                    <th>Document No</th>
                                    <th>Loan Date</th>
                                    <th>Penalty</th>
                                    <th>Penalty Date</th>
                                    <th>Remarks</th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.PenaltyItems.Count(); i++)
                                { 
                                    <tr>
                                        <td>
                                            @Html.ActionLink(Model.PenaltyItems[i].BorrowerName, "LoanJournal", "Loan", null, null, null, new { documentNo = Model.PenaltyItems[i].DocumentNo }, null)
                                            @Html.HiddenFor(m => m.PenaltyItems[i].BorrowerName)
                                        </td>
                                        <td>
                                            @Html.ActionLink(Model.PenaltyItems[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.PenaltyItems[i].DocumentNo }, null)
                                            @Html.HiddenFor(m => m.PenaltyItems[i].DocumentNo)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.PenaltyItems[i].DocumentDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.PenaltyItems[i].DocumentDate)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.PenaltyItems[i].Penalty, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.PenaltyItems[i].Penalty)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.PenaltyItems[i].PenaltyDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.PenaltyItems[i].PenaltyDate)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(m => m.PenaltyItems[i].Remarks)
                                            @Html.HiddenFor(m => m.PenaltyItems[i].Remarks)
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                    <div class="ibox-title">
                        <div class="pull-left">
                            <h3>Penalty Payments</h3>
                        </div>
                        <div class="pull-right">
                            <h3>
                                Total Paid Penalty: @Html.ValueFor(m => Model.TotalPenaltyPayment, "{0:#,###,##0.00}")
                                @Html.HiddenFor(m => Model.TotalPenaltyPayment)
                            </h3>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <table class="table table-bordered table-List">
                            <thead>
                                <tr>
                                    <th>Borrower</th>
                                    <th>Document No</th>
                                    <th>Loan Date</th>
                                    <th>Paid Penalty Amount</th>
                                    <th>Payment Date</th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.PenaltyPaymentItems.Count(); i++)
                                {
                                    <tr>
                                        <td>
                                            @Html.ActionLink(Model.PenaltyPaymentItems[i].BorrowerName, "LoanJournal", "Loan", null, null, null, new { documentNo = Model.PenaltyPaymentItems[i].DocumentNo }, null)
                                            @Html.HiddenFor(m => m.PenaltyPaymentItems[i].BorrowerName)
                                        </td>
                                        <td>
                                            @Html.ActionLink(Model.PenaltyPaymentItems[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.PenaltyPaymentItems[i].DocumentNo }, null)
                                            @Html.HiddenFor(m => m.PenaltyPaymentItems[i].DocumentNo)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.PenaltyPaymentItems[i].DocumentDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.PenaltyPaymentItems[i].DocumentDate)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.PenaltyPaymentItems[i].PaidPenaltyAmount, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.PenaltyPaymentItems[i].PaidPenaltyAmount)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.PenaltyPaymentItems[i].PaymentDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.PenaltyPaymentItems[i].PaymentDate)
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </fieldset>
            }
            </div>
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    @Styles.Render("~/plugins/dataPickerStyles")

    <style>

    select[disabled], select[disabled]:hover {
        pointer-events: none;
        color: #e1e1e1;
    }

    .divScroll {
        height: 400px;
        overflow-x: scroll;
        border: solid 1px #EBEBEB;
    }

    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
    }

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search td {
            margin: 10px 10px 10px 10px;
            padding: 10px 10px 10px 10px;
            vertical-align: bottom;
        }
        
        .table-search .tdAlignRight {
            text-align: right;
        }

        .table-search .tdFixed {
            width:20%;
        }

        .table-search .tdFixed div {
            margin-bottom: 0px;
        }

            .table-search td .btnSearch {
                margin-bottom: 0px;
            }

            
            .table-search td span {
                margin-left: 7px;
            }
</style>

}

@section Scripts {
@Scripts.Render("~/plugins/dataPicker")
@Scripts.Render("~/plugins/dataTables")

    <script id="methods" type="text/javascript">

        $(document).ready(function () {
            $('.table-List').dataTable({
                searching: false,
                paging: false,
                ordering: true,
                scrollY: 300

            });

            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    Refresh();
                    return false;
                }
            });

            SetDateFormat();
        });

        function SetDateFormat()
        {
            
            $('#fd .input-group.date').datepicker({
                todayBtn: "linked",
                keyboardNavigation: false,
                forceParse: false,
                calendarWeeks: true,
                format: 'mm/dd/yyyy',
                autoclose: true

            });

            $('#td .input-group.date').datepicker({
                todayBtn: "linked",
                keyboardNavigation: false,
                forceParse: false,
                calendarWeeks: true,
                format: 'mm/dd/yyyy',
                autoclose: true

            });

            var fd = $('#txtFromDate').val();
            $('#fd .input-group.date').datepicker("update", new Date(fd));

            var td = $('#txtToDate').val();
            $('#td .input-group.date').datepicker("update", new Date(td));
        }

        function Refresh() {
            SetDateFormat();
            document.getElementById('btnRefresh').click();
        }

    </script>
}